package 链表;

public class ListNode {

    public int val;
    public ListNode next;
    public ListNode() {}
    public ListNode(int val) { this.val = val; }
    public ListNode(int val, ListNode next) { this.val = val; this.next = next; }

    @Override
    public String toString(){
        return "val:"+val+"||next:"+next.val;
    }

    public static ListNode createListNode(int[] arr){
        return DG(arr, 0);
    }

    private static ListNode DG(int[] arr, int index){

        if(arr.length-1==index){
            return new ListNode(arr[index]);
        }

        ListNode listNode = new ListNode(arr[index]);

        listNode.next=DG(arr,index+1);

        return listNode;
    }

    public static void printListNode(ListNode cur){
        while (cur!=null){
            if(cur.next!=null)
                System.out.print(cur.val+"->");
            else
                System.out.print(cur.val);
            cur=cur.next;
        }
    }

    public static void main(String[] args) {
        int[] arr=new int[]{1,2,3,4,5};
        ListNode cur=createListNode(arr);
        printListNode(cur);
    }

}
